﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using VPBS.Common;

namespace VPBS.SqlClient.DAL
{
    public class TnDebtDAL
    {
        /// <summary>
        /// Lay danh sach danh muc chung khoan cua tung tai khoan
        /// </summary>
        /// <param ></param>
        /// <returns>DataSet Get_Debt</returns>
        public static decimal Get_Debt(string AccountNo)
        {
            try
            {
                string command =
                    @"select * from View_TN_THIEUTIEN_PHI_SUM where account_no='" + AccountNo + "'";
                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.PortalConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return decimal.Parse(ds.Tables[0].Rows[0]["sum_goc_comlai"].ToString());
                return 0m;
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_Debt), ex);
                return 0m;
            }
        }

        /// <summary>
        /// Danh sách tài khoản dư nợ Tn
        /// </summary>
        /// <returns></returns>
        public static DataSet Get_DebterLst()
        {
            try
            {
                string command =
                    @"select distinct account_no from THIEUTIEN 
                        where type=2 and isthanhly='False' and isthanhly_cap1='False' 
                        and account_no not in (select account from HMNTKVIP_groupacct)";
                DataSet ds = SqlHelper.ExecuteDataset(ConnectStringHelper.PortalConnectionString, CommandType.Text,
                                                      command);
                if (ds != null && ds.Tables.Count > 0)
                    return ds;
                return new DataSet();
            }
            catch (Exception ex)
            {
                //Logger.Error(typeof(Get_DebterLst), ex);
                return new DataSet();
            }
        }
    }
}
